package com.yu.mall.service;

import cn.hutool.core.util.StrUtil;
import com.yu.mall.entity.PostSales;
import com.yu.mall.entity.PostSalesExample;
import com.yu.mall.mapper.PostSalesMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Desc:
 * @Author: zhangyicheng
 * @Date: 2021/3/4
 */
@Service
@Transactional
@Slf4j
public class PostSalesService {

    @Resource
    PostSalesMapper postSalesMapper;

    public List<PostSales> pageQueryList(String openid,String status,String orderNo,String thirdApplyId,int pageNum, int pageSize) {
        PostSalesExample example = new PostSalesExample();
        PostSalesExample.Criteria criteria = example.createCriteria();
        criteria.andOpenidEqualTo(openid);
        if(StrUtil.isNotBlank(status)){
            criteria.andStatusEqualTo(status);
        }
        if(StrUtil.isNotBlank(orderNo)){
            criteria.andOrderNoEqualTo(orderNo);
        }
        if(StrUtil.isNotBlank(thirdApplyId)){
            criteria.andThirdApplyIdEqualTo(thirdApplyId);
        }
        example.setOffset((pageNum - 1l) * pageSize);
        example.setLimit(pageSize);
        example.setOrderByClause("create_datetime desc");
        return postSalesMapper.selectByExample(example);
    }
}
